package tool;

import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class LoadEnemyFiles {
	private String dirPath = "D:/Documents/runtime-workspace/test/";

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new LoadEnemyFiles();
	}
	
	public LoadEnemyFiles(){
		File dir = new File(dirPath);
		for(String file : dir.list()){
			if(file.endsWith("enm")){
				loadEnmFile(dirPath + file);
			}
		}
	}
	
	private void loadEnmFile(String path){
		FileInputStream fis = null;
		DataInputStream dis = null;
		
		try {
			fis = new FileInputStream(path);
			dis = new DataInputStream(fis);
			
			byte dataLen = 0;
			dataLen = dis.readByte();
			for (int i = 0; i < dataLen; i++) {
				String name = dis.readUTF();
				int hp = dis.readInt();
				byte mp = dis.readByte();
				byte at = dis.readByte();
				byte df = dis.readByte();
				byte dex = dis.readByte();
				int align = dis.readByte();
				byte xp = dis.readByte();
				byte enemyDrop = dis.readByte();
				byte icn = dis.readByte();
				byte[] enemyAlgo = new byte[4];
				for (int j = 0; j < 4; j++) {
					enemyAlgo[j] = dis.readByte();
				}
				byte enemyID = dis.readByte();
				
				System.out.println(
						name + "," +
						hp + "," +
						mp + "," +
						at + "," +
						df + "," +
						dex + "," +
						align + "," +
						xp + "," +
						enemyDrop + "," +
						icn + "," +
						enemyAlgo[0] + "," +
						enemyAlgo[1] + "," +
						enemyAlgo[2] + "," +
						enemyAlgo[3] + "," +
						enemyID
						);
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
